package com.ruoyi.controller.fanruan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.jpjs.common.fanruan.ZgFirst;
import com.ruoyi.service.fanruan.IZgFirstService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 筑工集团Controller
 *
 * @author ruoyi
 * @date 2020-11-04
 */
@Controller
@RequestMapping("/fanruan/zg")
public class ZgFirstController extends BaseController
{
    private String prefix = "fanruan/zg";

    @Autowired
    private IZgFirstService zgFirstService;

    @RequiresPermissions("fanruan:zg:view")
    @GetMapping()
    public String zg()
    {
        return "fanruan/zg/zg";
    }

    /**
     * 查询筑工集团列表
     */
    @RequiresPermissions("fanruan:zg:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZgFirst zgFirst)
    {
        startPage();
        List<ZgFirst> list = zgFirstService.selectZgFirstList(zgFirst);
        return getDataTable(list);
    }

    /**
     * 导出筑工集团列表
     */
    @RequiresPermissions("fanruan:zg:export")
    @Log(title = "筑工集团", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZgFirst zgFirst)
    {
        List<ZgFirst> list = zgFirstService.selectZgFirstList(zgFirst);
        ExcelUtil<ZgFirst> util = new ExcelUtil<ZgFirst>(ZgFirst.class);
        return util.exportExcel(list, "zg");
    }

    /**
     * 新增筑工集团
     */
    @GetMapping("/add")
    public String add()
    {
        return "fanruan/zg/add";
    }

    /**
     * 新增保存筑工集团
     */
    @RequiresPermissions("fanruan:zg:add")
    @Log(title = "筑工集团", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZgFirst zgFirst)
    {
        return toAjax(zgFirstService.insertZgFirst(zgFirst));
    }

    /**
     * 修改筑工集团
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZgFirst zgFirst = zgFirstService.selectZgFirstById(id);
        mmap.put("zgFirst", zgFirst);
        return "fanruan/zg/edit";
    }

    /**
     * 修改保存筑工集团
     */
    @RequiresPermissions("fanruan:zg:edit")
    @Log(title = "筑工集团", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZgFirst zgFirst)
    {
        return toAjax(zgFirstService.updateZgFirst(zgFirst));
    }

    /**
     * 删除筑工集团
     */
    @RequiresPermissions("fanruan:zg:remove")
    @Log(title = "筑工集团", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zgFirstService.deleteZgFirstByIds(ids));
    }
}
